package com.xingkeduo.service.common.typehandler;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;

import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;

public class DateIntTypeHandler extends BaseTypeHandler<Date> {
	public void setNonNullParameter(PreparedStatement preparedStatement, int i, Date date, JdbcType jdbcType)
			throws SQLException {
		preparedStatement.setInt(i, Integer.parseInt(String.valueOf(date.getTime()/1000)));
	}

	public Date getNullableResult(ResultSet resultSet, String s) throws SQLException {
		return new Date(((long)resultSet.getInt(s))*1000);
	}

	public Date getNullableResult(ResultSet resultSet, int i) throws SQLException {
		return new Date(((long)resultSet.getInt(i))*1000);
	}

	public Date getNullableResult(CallableStatement callableStatement, int i) throws SQLException {
		return new Date(((long)callableStatement.getInt(i))*1000);
	}
	
}
